
class P871_39643 {

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

	public static void main(String[] args) {
		
		int cases = Integer.parseInt(readLn());
		readLn();
		for (int k = 0; k < cases; k++) {
			process();
			
			if (k + 1 != cases) System.out.println();
			
		}
		
	}

	private static void process() {
		int[][] grid = new int[25][25];
		int n = 0, m = 0;
		
		String line = readLn();
		m = line.length();
		
		while (line != null && !"".equals(line)) {
			
			for (int k = 0; k < m; k++) { 
				grid[n][k] = line.charAt(k) - '0';
			}
			
			n++;
			
			line = readLn();
		}
		
		int max = 0;
		
		for (int k = 0; k < n; k++) {
			for (int j = 0; j < m; j++) {
				
				if (grid[k][j] == 1) {
					
					int length = flood(grid, k, j, n, m);
					
					if (max < length)
						max = length;
					
				}
				
			}
		}
		
		System.out.println(max);
		
	}

	private static int flood(int[][] grid, int k, int j, int n, int m) {
		int value = 0;
		
		if (grid[k][j] == 1) {
			grid[k][j] = -1;
			value++;
		 
		
			if (k + 1 < n) value += flood(grid, k+1, j, n, m);
			if (j + 1 < m) value += flood(grid, k, j+1, n, m);
			
			if (k - 1 >= 0) value += flood(grid, k-1, j, n, m);
			if (j - 1 >= 0) value += flood(grid, k, j-1, n, m);
			
			if (k + 1 < n && j + 1 < m) value += flood(grid, k+1, j+1, n, m);
			if (k - 1 >= 0 && j - 1 >= 0) value += flood(grid, k-1, j-1, n, m);
			
			if (k + 1 < n && j - 1 >= 0) value += flood(grid, k+1, j-1, n, m);
			if (k - 1 >= 0 && j + 1 < m) value += flood(grid, k-1, j+1, n, m);
			
			return value;
		
		} else {
			
			return value;
		}
	}
	
}
